package com.blak.black.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blak.black.common.CustomException;
import com.blak.black.entity.SetmealDish;
import com.blak.black.mapper.SetmealDishMapper;
import com.blak.black.service.SetmealDishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishMapper, SetmealDish> implements SetmealDishService {

    @Autowired
    private SetmealDishService setmealDishService;

    /**
     * 查询该菜品是否加入套餐
     * @param ids
     */
    @Transactional
    public boolean cha(List<Long> ids){
        LambdaQueryWrapper<SetmealDish> queryWrapper = new LambdaQueryWrapper<>();
        log.info("ids:{}",ids);
        queryWrapper.in(SetmealDish::getDishId,ids);
        int count=0;
        for(long id:ids){
            queryWrapper.eq(SetmealDish::getDishId,id);
            count = this.count(queryWrapper);
        }

     //   int count = this.count(queryWrapper);

        if (count>0) {
            return true;
        }
        return false;
    }
}
